#include "config.h"

#include "ms2lstat.h"

hist_t *
create_hist(void)
{
	hist_t	*hist;

	hist = (hist_t *)ecm_malloc(sizeof(hist_t));
	hist->n_max = 0;
	hist->n_count = 0;
	hist->data = (ecm_uint32 *)ecm_malloc(sizeof(ecm_uint32));
	hist->data[0] = 0;

	return hist;
}

void
add_hist(hist_t *hist, ecm_uint32 idx, ecm_uint32 cnt)
{
	if (hist->n_max < idx) {
		hist->data = (ecm_uint32 *)ecm_realloc(hist->data, sizeof(ecm_uint32) * (idx + 1));

		ecm_memset(hist->data + hist->n_max + 1, 0, sizeof(ecm_uint32) * (idx - hist->n_max));
		hist->n_max = idx;
	}
	hist->data[idx] += cnt;
	hist->n_count += cnt;
}

void
free_hist(hist_t *hist)
{
	ecm_free(hist->data);
	ecm_free(hist);
}
